<?php
/**
 * File: JsonReturn.class.php
 * Author: camy <375766145@qq.com>
 * Time: 2018/3/18 16:53
 */

namespace Common\Extend\Traits;

trait JsonReturn
{
    protected function jsonSuccess($data = [])
    {
        $return = array(
            'code' => 0,
            'data' => empty($data) ? [] : $data,
            'message' => 'OK',
        );
        return $this->jsonReturn($return);
    }

    protected function jsonFail($message = '', $code = -1)
    {
        $return = array(
            'code' => $code,
            'data' => [],
            'message' => empty($message) ? C('ERROR_MESSAGE') : $message,
        );
        return $this->jsonReturn($return);
    }

    protected function jsonReturn($data)
    {
        return $this->ajaxReturn($data,'json',JSON_UNESCAPED_UNICODE);
    }
}
